﻿using System;
using System.Threading.Tasks;
using System.Timers;

namespace EasyBackupService.Utils
{
    static class AppTimer
    {
        private static Timer _timer;

        public static void Start()
        {
            _timer = new Timer(60000D);
            _timer.AutoReset = true;
            _timer.Elapsed += new ElapsedEventHandler(Tick);
            _timer.Start();
        }

        public static void Stop()
        {
            try
            {
                _timer.Stop();
                _timer.Dispose();
                _timer = null;
            }
            catch { }
        }

        private static void Tick(object sender, EventArgs e)
        {
            Task.Run(() => Schedule.Check(DateTime.Now));
        }
    }
}
